﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FelMaster.Dev
{
    public partial class SpellLockWatcher : Form
    {
        private static SpellLockWatcher instance = new SpellLockWatcher();

        public static void Display()
        {
            if (instance == null || instance.IsDisposed)
                instance = new SpellLockWatcher();
            if (!instance.Visible)
            {
                instance.Show();
                instance.timer1.Start();
            }
        }

        private SpellLockWatcher()
        {
            InitializeComponent();
            paint();
        }

        private void paint()
        {
            this.Controls.Clear();

            var W = 400;
            var dy = 20;

            var y = 0;
            var locks = SimCraftBase.Instance.DumpSpellLocks();

            var col1 = 10;
            var col2 = (int)(col1 + (W - 20.0) * 0.6);
            var col3 = (int)(col2 + (W - 20.0) * 0.4 / 2.0);

            foreach (var x in locks)
            {
                var color = x.Value <= 0 ? Color.DarkGreen : Color.Red;

                var A = new Label();
                A.Text = x.Key;
                A.ForeColor = color;
                A.Size = new Size(col2 - col1, dy);
                A.TextAlign = ContentAlignment.MiddleLeft;
                A.Location = new Point(col1, y);

                var B = new Label();
                B.Text = x.Value.ToString();
                B.ForeColor = color;
                B.Size = new Size(col3 - col2, dy);
                B.TextAlign = ContentAlignment.MiddleLeft;
                B.Location = new Point(col2, y);

                var C = new Label();
                C.Text = SimCraftBase.Instance.TargetHasDebuff(x.Key) ? "Up" : "Down";
                C.ForeColor = color;
                C.Size = new Size(100, dy);
                C.TextAlign = ContentAlignment.MiddleLeft;
                C.Location = new Point(col3, y);

                this.Controls.Add(A);
                this.Controls.Add(B);
                this.Controls.Add(C);

                y += dy;
            }

            this.ClientSize = new Size(W, y + 80);
            this.MinimumSize = this.ClientSize;
            this.MaximumSize = this.ClientSize;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            paint();
        }
    }
}
